import 'dart:math';

import 'package:flutter/material.dart';

class TestAnimPage extends StatefulWidget {
  _TestAnimPageState createState() => new _TestAnimPageState();
}

class _TestAnimPageState extends State<TestAnimPage> with SingleTickerProviderStateMixin {
  Animation<double> animation;
  AnimationController controller;

  initState() {
    super.initState();
    controller = new AnimationController(duration: const Duration(milliseconds: 2000), vsync: this);
    animation = new Tween(begin: 0.0, end: 2.0 * pi).animate(controller)
      ..addStatusListener((status) {
        if (status == AnimationStatus.completed) {
          controller.reverse();
        } else if (status == AnimationStatus.dismissed) {
          controller.forward();
        }
      });
    // ..addListener(() {
    //   setState(() {
    //     // the state that has changed here is the animation object’s value
    //   });
    // });
    controller.forward();
  }

  Widget build(BuildContext context) {
    // return new Center(
    //   child: new Container(
    //     margin: new EdgeInsets.symmetric(vertical: 10.0),
    //     height: animation.value,
    //     width: animation.value,
    //     child: new FlutterLogo(),
    //   ),
    // );
    return AnimatedBuilder(
      animation: animation,
      builder: (BuildContext context, Widget child) {
        return Transform.rotate(
          angle: animation.value,
          child: child,
        );
      },
      child: FlutterLogo(
        size: 60,
      ),
    );
  }

  dispose() {
    controller.dispose();
    super.dispose();
  }
}
